(function($) {
	$.fn.multiSelector = function(config) {
		if (typeof config == 'string') {
			var fn = $.jqInvoke.getAccessor($.multipleSelector,config);
			if (!fn) {
				alert("$.multipleSelector - 未找到匹配的校验方法 : " + config);
				//throw ("$.jqValidator - No such method: " + config);
				return;
			}
			var args = $.makeArray(arguments).slice(1);
			return fn.apply(this,args);
		}
		
		return this.each(function() {
			
			/**
			 * 防止重复初始化
			 */
			if(this.completed){return;}
			
			/**
			 * 1)当前multiSelector控件jquery对象,
			 * 2)"已选"select控件,
			 * 3)"待选"select控件,
			 * 4)"移至已选"按钮控件,
			 * 5)"移至待选"按钮控件;
			 **/
			var $this = $(this);
			
			var _config = $.extend({},{id:$this.attr('id')},config)
			
			_config.multipleSelectDestiId = "multipleSelectDesti"+$.StringUtils.firstUpperCase(_config.id);
			_config.multipleSelectSourceId = "multipleSelectSource"+$.StringUtils.firstUpperCase(_config.id);
			_config.btnToDestiId = "btnToDesti"+$.StringUtils.firstUpperCase(_config.id);
			_config.btnToSourceId = "btnToSource"+$.StringUtils.firstUpperCase(_config.id);
			_config.btnClearId = "btnClear"+$.StringUtils.firstUpperCase(_config.id);
			
			var $multipleSelectDesti = $("#"+_config.multipleSelectDestiId),
			$multipleSelectSource = $("#"+_config.multipleSelectSourceId),
			$btnToDesti = $("#"+_config.btnToDestiId),
			$btnToSource = $("#"+_config.btnToSourceId),
			$btnClear = $("#"+_config.btnClearId);
			
			/**
			 * 待选下拉(注册事件)
			 */
			$multipleSelectSource.bind("dblclick",function(){
				$this.multiSelector("sourceToDesti");
			});
			
			/**
			 * 已选下拉
			 */
			$multipleSelectDesti.bind("dblclick",function(){
				$this.multiSelector("destiToSource");
			});
			
			
			/**
			 * 待选移至已选 按钮(注册事件)
			 */
			$btnToDesti.bind("click",function(){
				$this.multiSelector("sourceToDesti");
			});
			
			/**
			 * 已选移至待选 按钮(注册事件)
			 */
			$btnToSource.bind("click",function(){
				$this.multiSelector("destiToSource");
			});
			
			/**
			 * 已选全部移至待选 按钮(注册事件)
			 */
			$btnClear.bind("click",function(){
				$this.multiSelector("destiAllToSource");
			});
			
			/**
			 * 国际化处理
			 */
			if(_config.id){
				$btnToDesti.attr("title",$.multipleSelector.i18n.btnToDesti.title);
				$btnToSource.attr("title",$.multipleSelector.i18n.btnToSource.title);
				$btnClear.attr("title",$.multipleSelector.i18n.btnClear.title);
				
				var $legendSource = $("#legendSource"+$.StringUtils.firstUpperCase(_config.id));
				if($.StringUtils.isEmpty($legendSource.text())){
					$legendSource.text($.multipleSelector.i18n.legendSource.text);
				}
				
				var $legendDesti =  $("#legendDesti"+$.StringUtils.firstUpperCase(_config.id));
				if($.StringUtils.isEmpty($legendDesti.text())){
					$legendDesti.text($.multipleSelector.i18n.legendDesti.text);
				}
			}
			
			
			this.config = _config;
			this.completed = true;
		});
	};
})(jQuery);